<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NumCpp: Brent.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="NumCppLogoDoxygen.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">NumCpp
   &#160;<span id="projectnumber">2.3.1</span>
   </div>
   <div id="projectbrief">A Templatized Header Only C++ Implementation of the Python NumPy Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_brent_8hpp_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Brent.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_brent_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#pragma once</span></div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160; </div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_dtype_info_8hpp.html">NumCpp/Core/DtypeInfo.hpp</a>&quot;</span></div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_types_8hpp.html">NumCpp/Core/Types.hpp</a>&quot;</span></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_iteration_8hpp.html">NumCpp/Roots/Iteration.hpp</a>&quot;</span></div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160; </div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<span class="preprocessor">#include &lt;cmath&gt;</span></div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="preprocessor">#include &lt;functional&gt;</span></div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;<span class="preprocessor">#include &lt;utility&gt;</span></div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160; </div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacenc.html">nc</a></div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;{</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    <span class="keyword">namespace </span>roots</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    {</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;        <span class="comment">//================================================================================</span></div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;        <span class="comment">// Class Description:</span></div>
<div class="line"><a name="l00050"></a><span class="lineno"><a class="line" href="classnc_1_1roots_1_1_brent.html">   50</a></span>&#160;<span class="comment"></span>        <span class="keyword">class </span><a class="code" href="classnc_1_1roots_1_1_brent.html">Brent</a> : <span class="keyword">public</span> <a class="code" href="classnc_1_1roots_1_1_iteration.html">Iteration</a></div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;        {</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;        <span class="keyword">public</span>:</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;            <span class="comment">//============================================================================</span></div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;            <span class="comment">// Method Description:</span></div>
<div class="line"><a name="l00060"></a><span class="lineno"><a class="line" href="classnc_1_1roots_1_1_brent.html#aecf6662d1b7128d38796cf4ab99143f4">   60</a></span>&#160;<span class="comment"></span>            <a class="code" href="classnc_1_1roots_1_1_brent.html#aecf6662d1b7128d38796cf4ab99143f4">Brent</a>(<span class="keyword">const</span> <span class="keywordtype">double</span> epsilon,</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;                std::function&lt;<span class="keywordtype">double</span>(<span class="keywordtype">double</span>)&gt;  <a class="code" href="namespacenc_1_1random.html#a00229c23da25284daf436c0a338ea25c">f</a>) noexcept :</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;                <a class="code" href="classnc_1_1roots_1_1_iteration.html#a2d7285a81c033d56ce8283b6dbfca136">Iteration</a>(epsilon),</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;                f_(std::move(<a class="code" href="namespacenc_1_1random.html#a00229c23da25284daf436c0a338ea25c">f</a>))</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;            {}</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160; </div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;            <span class="comment">//============================================================================</span></div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;            <span class="comment">// Method Description:</span></div>
<div class="line"><a name="l00074"></a><span class="lineno"><a class="line" href="classnc_1_1roots_1_1_brent.html#a1e9cf8f7be13c7bbb42a073ec9eb5369">   74</a></span>&#160;<span class="comment"></span>            <a class="code" href="classnc_1_1roots_1_1_brent.html#a1e9cf8f7be13c7bbb42a073ec9eb5369">Brent</a>(<span class="keyword">const</span> <span class="keywordtype">double</span> epsilon,</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;                <span class="keyword">const</span> <a class="code" href="namespacenc.html#af0f49663fb63332596e2e6327009d581">uint32</a> maxNumIterations, </div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;                std::function&lt;<span class="keywordtype">double</span>(<span class="keywordtype">double</span>)&gt;  <a class="code" href="namespacenc_1_1random.html#a00229c23da25284daf436c0a338ea25c">f</a>) noexcept :</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;                <a class="code" href="classnc_1_1roots_1_1_iteration.html#a2d7285a81c033d56ce8283b6dbfca136">Iteration</a>(epsilon, maxNumIterations),</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;                f_(std::move(<a class="code" href="namespacenc_1_1random.html#a00229c23da25284daf436c0a338ea25c">f</a>))</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;            {}</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160; </div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;            <span class="comment">//============================================================================</span></div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;            <span class="comment">// Method Description:</span></div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;<span class="comment"></span>            <a class="code" href="classnc_1_1roots_1_1_brent.html#ade76ad260d82314f284ebacf885f6884">~Brent</a>() <span class="keyword">override</span> = <span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160; </div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;            <span class="comment">//============================================================================</span></div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;            <span class="comment">// Method Description:</span></div>
<div class="line"><a name="l00095"></a><span class="lineno"><a class="line" href="classnc_1_1roots_1_1_brent.html#a3853981ca1113723006b6627d96d378b">   95</a></span>&#160;<span class="comment"></span>            <span class="keywordtype">double</span> <a class="code" href="classnc_1_1roots_1_1_brent.html#a3853981ca1113723006b6627d96d378b">solve</a>(<span class="keywordtype">double</span> a, <span class="keywordtype">double</span> b)</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;            {</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;                <a class="code" href="classnc_1_1roots_1_1_iteration.html#a85e79a4794bc3a6ac6bc3564956737a2">resetNumberOfIterations</a>();</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160; </div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;                <span class="keywordtype">double</span> fa = f_(a);</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;                <span class="keywordtype">double</span> fb = f_(b);</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160; </div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;                checkAndFixAlgorithmCriteria(a, b, fa, fb);</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160; </div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;                <span class="keywordtype">double</span> lastB = a; <span class="comment">// b_{k-1}</span></div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;                <span class="keywordtype">double</span> lastFb = fa;</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;                <span class="keywordtype">double</span> s = <a class="code" href="classnc_1_1_dtype_info.html#a2a3dc0ba2812411660219f61189d8aca">DtypeInfo&lt;double&gt;::max</a>();</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;                <span class="keywordtype">double</span> fs = <a class="code" href="classnc_1_1_dtype_info.html#a2a3dc0ba2812411660219f61189d8aca">DtypeInfo&lt;double&gt;::max</a>();</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;                <span class="keywordtype">double</span> penultimateB = a; <span class="comment">// b_{k-2}</span></div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160; </div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;                <span class="keywordtype">bool</span> bisection = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;                <span class="keywordflow">while</span> (std::fabs(fb) &gt; <a class="code" href="classnc_1_1roots_1_1_iteration.html#a5eafe219bb90f82da4ece84f012a411a">epsilon_</a> &amp;&amp; std::fabs(fs) &gt; <a class="code" href="classnc_1_1roots_1_1_iteration.html#a5eafe219bb90f82da4ece84f012a411a">epsilon_</a> &amp;&amp; std::fabs(b - a) &gt; <a class="code" href="classnc_1_1roots_1_1_iteration.html#a5eafe219bb90f82da4ece84f012a411a">epsilon_</a>)</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;                {</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;                    <span class="keywordflow">if</span> (useInverseQuadraticInterpolation(fa, fb, lastFb))</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;                    {</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;                        s = calculateInverseQuadraticInterpolation(a, b, lastB, fa, fb, lastFb);</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;                    }</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;                    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;                    {</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;                        s = calculateSecant(a, b, fa, fb);</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;                    }</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160; </div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;                    <span class="keywordflow">if</span> (useBisection(bisection, b, lastB, penultimateB, s))</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;                    {</div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;                        s = calculateBisection(a, b);</div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;                        bisection = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;                    }</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;                    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;                    {</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;                        bisection = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;                    }</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160; </div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;                    fs = f_(s);</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;                    penultimateB = lastB;</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;                    lastB = b;</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160; </div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;                    <span class="keywordflow">if</span> (fa * fs &lt; 0)</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;                    {</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;                        b = s;</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;                    }</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;                    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;                        a = s;</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;                    }</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160; </div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;                    fa = f_(a);</div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;                    lastFb = fb;</div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;                    fb = f_(b);</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;                    checkAndFixAlgorithmCriteria(a, b, fa, fb);</div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160; </div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;                    <a class="code" href="classnc_1_1roots_1_1_iteration.html#ad0262a1a694e734ebc154c77f010bcff">incrementNumberOfIterations</a>();</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;                }</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160; </div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;                <span class="keywordflow">return</span> fb &lt; fs ? b : s;</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;            }</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160; </div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;        <span class="keyword">private</span>:</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;            <span class="comment">//============================================================================</span></div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;            <span class="keyword">const</span> std::function&lt;double(<span class="keywordtype">double</span>)&gt; f_;</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160; </div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;            <span class="comment">//============================================================================</span></div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;            <span class="comment">// Method Description:</span></div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;<span class="comment"></span>            <span class="keyword">static</span> <span class="keywordtype">double</span> calculateBisection(<span class="keyword">const</span> <span class="keywordtype">double</span> a, <span class="keyword">const</span> <span class="keywordtype">double</span> b) noexcept </div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;            {</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;                <span class="keywordflow">return</span> 0.5 * (a + b);</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;            }</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160; </div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;            <span class="comment">//============================================================================</span></div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;            <span class="comment">// Method Description:</span></div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;<span class="comment"></span>            <span class="keyword">static</span> <span class="keywordtype">double</span> calculateSecant(<span class="keyword">const</span> <span class="keywordtype">double</span> a, <span class="keyword">const</span> <span class="keywordtype">double</span> b, <span class="keyword">const</span> <span class="keywordtype">double</span> fa, <span class="keyword">const</span> <span class="keywordtype">double</span> fb) noexcept </div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;            {</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;                <span class="comment">//No need to check division by 0, in this case the method returns NAN which is taken care by useSecantMethod method</span></div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;                <span class="keywordflow">return</span> b - fb * (b - a) / (fb - fa);</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;            }</div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160; </div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;            <span class="comment">//============================================================================</span></div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;            <span class="comment">// Method Description:</span></div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;<span class="comment"></span>            <span class="keyword">static</span> <span class="keywordtype">double</span> calculateInverseQuadraticInterpolation(<span class="keyword">const</span> <span class="keywordtype">double</span> a, <span class="keyword">const</span> <span class="keywordtype">double</span> b, <span class="keyword">const</span> <span class="keywordtype">double</span> lastB,</div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;                <span class="keyword">const</span> <span class="keywordtype">double</span> fa, <span class="keyword">const</span> <span class="keywordtype">double</span> fb, <span class="keyword">const</span> <span class="keywordtype">double</span> lastFb) noexcept </div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;            {</div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;                <span class="keywordflow">return</span> a * fb * lastFb / ((fa - fb) * (fa - lastFb)) +</div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;                    b * fa * lastFb / ((fb - fa) * (fb - lastFb)) +</div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;                    lastB * fa * fb / ((lastFb - fa) * (lastFb - fb));</div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;            }</div>
<div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160; </div>
<div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;            <span class="comment">//============================================================================</span></div>
<div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;            <span class="comment">// Method Description:</span></div>
<div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;<span class="comment"></span>            <span class="keyword">static</span> <span class="keywordtype">bool</span> useInverseQuadraticInterpolation(<span class="keyword">const</span> <span class="keywordtype">double</span> fa, <span class="keyword">const</span> <span class="keywordtype">double</span> fb, <span class="keyword">const</span> <span class="keywordtype">double</span> lastFb) noexcept </div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;            {</div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;                <span class="keywordflow">return</span> fa != lastFb &amp;&amp; fb != lastFb;</div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;            }</div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160; </div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;            <span class="comment">//============================================================================</span></div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;            <span class="comment">// Method Description:</span></div>
<div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;<span class="comment"></span>            <span class="keyword">static</span> <span class="keywordtype">void</span> checkAndFixAlgorithmCriteria(<span class="keywordtype">double</span> &amp;a, <span class="keywordtype">double</span> &amp;b, <span class="keywordtype">double</span> &amp;fa, <span class="keywordtype">double</span> &amp;fb) noexcept </div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;            {</div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;                <span class="comment">//Algorithm works in range [a,b] if criteria f(a)*f(b) &lt; 0 and f(a) &gt; f(b) is fulfilled</span></div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;                <span class="keywordflow">if</span> (std::fabs(fa) &lt; std::fabs(fb))</div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;                {</div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;                    <a class="code" href="namespacenc.html#a39da0502565b913855379ea1439047e1">std::swap</a>(a, b);</div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;                    <a class="code" href="namespacenc.html#a39da0502565b913855379ea1439047e1">std::swap</a>(fa, fb);</div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;                }</div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;            }</div>
<div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160; </div>
<div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;            <span class="comment">//============================================================================</span></div>
<div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;            <span class="comment">// Method Description:</span></div>
<div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;<span class="comment"></span>            <span class="keywordtype">bool</span> useBisection(<span class="keyword">const</span> <span class="keywordtype">bool</span> bisection, <span class="keyword">const</span> <span class="keywordtype">double</span> b, <span class="keyword">const</span> <span class="keywordtype">double</span> lastB,</div>
<div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;                <span class="keyword">const</span> <span class="keywordtype">double</span> penultimateB, <span class="keyword">const</span> <span class="keywordtype">double</span> s) <span class="keyword">const</span> noexcept </div>
<div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;            {</div>
<div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;                <span class="keyword">const</span> <span class="keywordtype">double</span> DELTA = <a class="code" href="classnc_1_1roots_1_1_iteration.html#a5eafe219bb90f82da4ece84f012a411a">epsilon_</a> + <a class="code" href="namespacenc.html#a8a61a49362258590b70289fd63fb2d8e">std::numeric_limits&lt;double&gt;::min</a>();</div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160; </div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;                <span class="keywordflow">return</span> (bisection &amp;&amp; std::fabs(s - b) &gt;= 0.5 * std::fabs(b - lastB)) || <span class="comment">//Bisection was used in last step but |s-b|&gt;=|b-lastB|/2 &lt;- Interpolation step would be to rough, so still use bisection</span></div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;                    (!bisection &amp;&amp; std::fabs(s - b) &gt;= 0.5 * std::fabs(lastB - penultimateB)) || <span class="comment">//Interpolation was used in last step but |s-b|&gt;=|lastB-penultimateB|/2 &lt;- Interpolation step would be to small</span></div>
<div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;                    (bisection &amp;&amp; std::fabs(b - lastB) &lt; DELTA) || <span class="comment">//If last iteration was using bisection and difference between b and lastB is &lt; delta use bisection for next iteration</span></div>
<div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;                    (!bisection &amp;&amp; std::fabs(lastB - penultimateB) &lt; DELTA); <span class="comment">//If last iteration was using interpolation but difference between lastB ond penultimateB is &lt; delta use biscetion for next iteration</span></div>
<div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;            }</div>
<div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;        };</div>
<div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;    }  <span class="comment">// namespace roots</span></div>
<div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;} <span class="comment">// namespace nc</span></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="aclassnc_1_1roots_1_1_iteration_html_a2d7285a81c033d56ce8283b6dbfca136"><div class="ttname"><a href="classnc_1_1roots_1_1_iteration.html#a2d7285a81c033d56ce8283b6dbfca136">nc::roots::Iteration::Iteration</a></div><div class="ttdeci">Iteration(double epsilon) noexcept</div><div class="ttdef"><b>Definition:</b> Iteration.hpp:55</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_brent_html"><div class="ttname"><a href="classnc_1_1roots_1_1_brent.html">nc::roots::Brent</a></div><div class="ttdef"><b>Definition:</b> Brent.hpp:50</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_iteration_html"><div class="ttname"><a href="classnc_1_1roots_1_1_iteration.html">nc::roots::Iteration</a></div><div class="ttdoc">ABC for iteration classes to derive from.</div><div class="ttdef"><b>Definition:</b> Iteration.hpp:46</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_brent_html_a1e9cf8f7be13c7bbb42a073ec9eb5369"><div class="ttname"><a href="classnc_1_1roots_1_1_brent.html#a1e9cf8f7be13c7bbb42a073ec9eb5369">nc::roots::Brent::Brent</a></div><div class="ttdeci">Brent(const double epsilon, const uint32 maxNumIterations, std::function&lt; double(double)&gt; f) noexcept</div><div class="ttdef"><b>Definition:</b> Brent.hpp:74</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_brent_html_ade76ad260d82314f284ebacf885f6884"><div class="ttname"><a href="classnc_1_1roots_1_1_brent.html#ade76ad260d82314f284ebacf885f6884">nc::roots::Brent::~Brent</a></div><div class="ttdeci">~Brent() override=default</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_iteration_html_ad0262a1a694e734ebc154c77f010bcff"><div class="ttname"><a href="classnc_1_1roots_1_1_iteration.html#ad0262a1a694e734ebc154c77f010bcff">nc::roots::Iteration::incrementNumberOfIterations</a></div><div class="ttdeci">void incrementNumberOfIterations()</div><div class="ttdef"><b>Definition:</b> Iteration.hpp:104</div></div>
<div class="ttc" id="anamespacenc_html_af0f49663fb63332596e2e6327009d581"><div class="ttname"><a href="namespacenc.html#af0f49663fb63332596e2e6327009d581">nc::uint32</a></div><div class="ttdeci">std::uint32_t uint32</div><div class="ttdef"><b>Definition:</b> Types.hpp:40</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_iteration_html_a5eafe219bb90f82da4ece84f012a411a"><div class="ttname"><a href="classnc_1_1roots_1_1_iteration.html#a5eafe219bb90f82da4ece84f012a411a">nc::roots::Iteration::epsilon_</a></div><div class="ttdeci">const double epsilon_</div><div class="ttdef"><b>Definition:</b> Iteration.hpp:114</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_brent_html_aecf6662d1b7128d38796cf4ab99143f4"><div class="ttname"><a href="classnc_1_1roots_1_1_brent.html#aecf6662d1b7128d38796cf4ab99143f4">nc::roots::Brent::Brent</a></div><div class="ttdeci">Brent(const double epsilon, std::function&lt; double(double)&gt; f) noexcept</div><div class="ttdef"><b>Definition:</b> Brent.hpp:60</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_brent_html_a3853981ca1113723006b6627d96d378b"><div class="ttname"><a href="classnc_1_1roots_1_1_brent.html#a3853981ca1113723006b6627d96d378b">nc::roots::Brent::solve</a></div><div class="ttdeci">double solve(double a, double b)</div><div class="ttdef"><b>Definition:</b> Brent.hpp:95</div></div>
<div class="ttc" id="a_iteration_8hpp_html"><div class="ttname"><a href="_iteration_8hpp.html">Iteration.hpp</a></div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_iteration_html_a85e79a4794bc3a6ac6bc3564956737a2"><div class="ttname"><a href="classnc_1_1roots_1_1_iteration.html#a85e79a4794bc3a6ac6bc3564956737a2">nc::roots::Iteration::resetNumberOfIterations</a></div><div class="ttdeci">void resetNumberOfIterations() noexcept</div><div class="ttdef"><b>Definition:</b> Iteration.hpp:93</div></div>
<div class="ttc" id="anamespacenc_html"><div class="ttname"><a href="namespacenc.html">nc</a></div><div class="ttdef"><b>Definition:</b> Coordinate.hpp:44</div></div>
<div class="ttc" id="anamespacenc_html_a39da0502565b913855379ea1439047e1"><div class="ttname"><a href="namespacenc.html#a39da0502565b913855379ea1439047e1">nc::swap</a></div><div class="ttdeci">void swap(NdArray&lt; dtype &gt; &amp;inArray1, NdArray&lt; dtype &gt; &amp;inArray2) noexcept</div><div class="ttdef"><b>Definition:</b> swap.hpp:42</div></div>
<div class="ttc" id="a_dtype_info_8hpp_html"><div class="ttname"><a href="_dtype_info_8hpp.html">DtypeInfo.hpp</a></div></div>
<div class="ttc" id="a_types_8hpp_html"><div class="ttname"><a href="_types_8hpp.html">Types.hpp</a></div></div>
<div class="ttc" id="anamespacenc_1_1random_html_a00229c23da25284daf436c0a338ea25c"><div class="ttname"><a href="namespacenc_1_1random.html#a00229c23da25284daf436c0a338ea25c">nc::random::f</a></div><div class="ttdeci">dtype f(dtype inDofN, dtype inDofD)</div><div class="ttdef"><b>Definition:</b> f.hpp:57</div></div>
<div class="ttc" id="aclassnc_1_1_dtype_info_html_a2a3dc0ba2812411660219f61189d8aca"><div class="ttname"><a href="classnc_1_1_dtype_info.html#a2a3dc0ba2812411660219f61189d8aca">nc::DtypeInfo::max</a></div><div class="ttdeci">static constexpr dtype max() noexcept</div><div class="ttdef"><b>Definition:</b> DtypeInfo.hpp:110</div></div>
<div class="ttc" id="anamespacenc_html_a8a61a49362258590b70289fd63fb2d8e"><div class="ttname"><a href="namespacenc.html#a8a61a49362258590b70289fd63fb2d8e">nc::min</a></div><div class="ttdeci">NdArray&lt; dtype &gt; min(const NdArray&lt; dtype &gt; &amp;inArray, Axis inAxis=Axis::NONE)</div><div class="ttdef"><b>Definition:</b> min.hpp:45</div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_34171bd951b13a53aa9f237277a18e40.html">NumCpp</a></li><li class="navelem"><a class="el" href="dir_22368e90b3593b912515c50bf54c969c.html">Roots</a></li><li class="navelem"><a class="el" href="_brent_8hpp.html">Brent.hpp</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.17 </li>
  </ul>
</div>
</body>
</html>
